<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.plugs.alias &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="up" title="gozerlib.plugs" href="index.html" />
    <link rel="next" title="gozerlib.plugs.choice" href="choice.html" />
    <link rel="prev" title="gozerlib.plugs.admin" href="admin.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="choice.html" title="gozerlib.plugs.choice"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="admin.html" title="gozerlib.plugs.admin"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">gozerlib.plugs</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.plugs.alias">
<h1>gozerlib.plugs.alias<a class="headerlink" href="#module-gozerlib.plugs.alias" title="Permalink to this headline">¶</a></h1>
<p>this alias plugin allows aliases for commands to be added. aliases are in
the form of &lt;alias&gt; -&gt; &lt;command&gt; .. aliases to aliases are not allowed.</p>
<dl class="function">
<dt id="gozerlib.plugs.alias.handle_aliassearch">
<tt class="descclassname">gozerlib.plugs.alias.</tt><tt class="descname">handle_aliassearch</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.alias.handle_aliassearch" title="Permalink to this definition">¶</a></dt>
<dd>alias-search &lt;what&gt; .. search aliases.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.alias.handle_aliasset">
<tt class="descclassname">gozerlib.plugs.alias.</tt><tt class="descname">handle_aliasset</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.alias.handle_aliasset" title="Permalink to this definition">¶</a></dt>
<dd>alias-set &lt;from&gt; &lt;to&gt; .. set alias.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.alias.handle_delalias">
<tt class="descclassname">gozerlib.plugs.alias.</tt><tt class="descname">handle_delalias</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.alias.handle_delalias" title="Permalink to this definition">¶</a></dt>
<dd>alias-del &lt;word&gt; .. delete alias.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.alias.handle_getalias">
<tt class="descclassname">gozerlib.plugs.alias.</tt><tt class="descname">handle_getalias</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.alias.handle_getalias" title="Permalink to this definition">¶</a></dt>
<dd>alias-get &lt;word&gt; .. show alias.</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127</pre></td><td class="code"><div class="highlight"><pre><span class="c"># plugs/alias.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; </span>
<span class="sd">    this alias plugin allows aliases for commands to be added. aliases are in</span>
<span class="sd">    the form of &lt;alias&gt; -&gt; &lt;command&gt; .. aliases to aliases are not allowed.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="c"># gozerlib imports</span>
<span class="kn">from</span> <span class="nn">gozerlib.aliases</span> <span class="kn">import</span> <span class="n">aliasget</span><span class="p">,</span> <span class="n">aliasdel</span><span class="p">,</span> <span class="n">aliasset</span><span class="p">,</span> <span class="n">getaliases</span>
<span class="kn">from</span> <span class="nn">gozerlib.commands</span> <span class="kn">import</span> <span class="n">cmnds</span>
<span class="kn">from</span> <span class="nn">gozerlib.examples</span> <span class="kn">import</span> <span class="n">examples</span>

<span class="c"># basuc imports</span>
<span class="kn">import</span> <span class="nn">os</span>

<span class="k">def</span> <span class="nf">handle_aliassearch</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; alias-search &lt;what&gt; .. search aliases. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;what&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">aliases</span> <span class="o">=</span> <span class="n">getaliases</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">aliases</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">what</span> <span class="ow">in</span> <span class="n">i</span> <span class="ow">or</span> <span class="n">what</span> <span class="ow">in</span> <span class="n">j</span><span class="p">:</span>
            <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">))</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no </span><span class="si">%s</span><span class="s"> found&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
            <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> =&gt; </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">i</span><span class="p">)</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;aliases matching </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">what</span><span class="p">,</span> <span class="n">res</span><span class="p">,</span> <span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;alias-search&#39;</span><span class="p">,</span> <span class="n">handle_aliassearch</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;alias-search&#39;</span><span class="p">,</span> <span class="s">&#39;search aliases&#39;</span><span class="p">,</span><span class="s">&#39; alias-search web&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;alias-set mekker miep&#39;).add(&#39;alias-search mekker&#39;, &#39;miep&#39;).add(&#39;alias-del mekker&#39;)</span>

<span class="k">def</span> <span class="nf">handle_aliasset</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; alias-set &lt;from&gt; &lt;to&gt; .. set alias. &quot;&quot;&quot;</span>

    <span class="n">aliases</span> <span class="o">=</span> <span class="n">getaliases</span><span class="p">()</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="p">(</span><span class="n">aliasfrom</span><span class="p">,</span> <span class="n">aliasto</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="s">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">1</span><span class="p">:]))</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;from&gt; &lt;to&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">aliasto</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;from&gt; &lt;to&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">aliases</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">aliasto</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t alias an alias&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="n">cmnds</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">aliasfrom</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;command with same name already exists.&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="c"># add alias and save</span>
    <span class="n">aliasset</span><span class="p">(</span><span class="n">aliasfrom</span><span class="p">,</span> <span class="n">aliasto</span><span class="p">)</span>
    <span class="n">aliases</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;alias added&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;alias-set&#39;</span><span class="p">,</span> <span class="n">handle_aliasset</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">,</span> <span class="n">allowqueue</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;alias-set&#39;</span><span class="p">,</span> <span class="s">&#39;alias-set &lt;alias&gt; &lt;command&gt; .. define alias&#39;</span><span class="p">,</span> \
<span class="s">&#39;alias-set ll list&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;alias&#39;</span><span class="p">,</span> <span class="s">&#39;alias-set&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;alias-set mekker2 list&#39;, &#39;alias added&#39;).add(&#39;mekker2&#39;, &#39;grep&#39;).add(&#39;alias-del mekker2&#39;)</span>

<span class="k">def</span> <span class="nf">handle_delalias</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; alias-del &lt;word&gt; .. delete alias. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;what&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="c"># del alias and save</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">aliasdel</span><span class="p">(</span><span class="n">what</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;there is no </span><span class="si">%s</span><span class="s"> alias&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">aliases</span> <span class="o">=</span> <span class="n">getaliases</span><span class="p">()</span>
    <span class="n">aliases</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;alias deleted&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;alias-del&#39;</span><span class="p">,</span> <span class="n">handle_delalias</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;alias-del&#39;</span><span class="p">,</span> <span class="s">&#39;alias-del &lt;what&gt; .. delete alias&#39;</span><span class="p">,</span> <span class="s">&#39;alias-del ll&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;alias-set mekker3 miep&#39;).add(&#39;alias-del mekker3&#39;, &#39;alias deleted&#39;)</span>

<span class="k">def</span> <span class="nf">handle_getalias</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; alias-get &lt;word&gt; .. show alias. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;what&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>
    <span class="c"># del alias and save</span>

    <span class="n">alias</span> <span class="o">=</span> <span class="n">aliasget</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">alias</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;there is no </span><span class="si">%s</span><span class="s"> alias&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">alias</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;alias-get&#39;</span><span class="p">,</span> <span class="n">handle_getalias</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;alias-get&#39;</span><span class="p">,</span> <span class="s">&#39;alias-get &lt;what&gt; .. get alias&#39;</span><span class="p">,</span> <span class="s">&#39;alias-get v&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;alias-set mekker4 miep&#39;).add(&#39;alias-get mekker4&#39;, &#39;miep&#39;).add(&#39;alias-del mekker4&#39;)</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.plugs.alias</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="admin.html"
                                  title="previous chapter">gozerlib.plugs.admin</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="choice.html"
                                  title="next chapter">gozerlib.plugs.choice</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/plugs/alias.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="choice.html" title="gozerlib.plugs.choice"
             >next</a> |</li>
        <li class="right" >
          <a href="admin.html" title="gozerlib.plugs.admin"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" >gozerlib.plugs</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>